package net.dntuan.training.spring.mvc;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Control endpoints (start or stop)
 *
 * @author tuan.dangnhu
 *
 * $LastChangedRevision: 122 $
 * $LastChangedDate: 2014-10-06 03:05:04 +0000 (Mon, 06 Oct 2014) $
 * $LastChangedBy: dnhutuan@gmail.com $
 */
@Controller
@RequestMapping("ctrl")
public class ControlBusController {

  @Autowired
  private MessageChannel controlChannel;

  @RequestMapping("/{activity}/{endpoint}")
  @ResponseBody
  public boolean controlEndpoint(@PathVariable("endpoint") String endpoint, @PathVariable("activity") String activity) {
    return controlChannel.send(new GenericMessage<String>("@" + endpoint + "." + activity + "()"));
  }
}
